<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

class Reception extends Model
{
    use HasDateTimeFormatter, SoftDeletes;

    protected $guarded = [];


    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }
    //品牌资质
    public function brand(): BelongsTo
    {
        return $this->belongsTo(Option::class, 'brand_option_id');
    }


    //根据下标获取微信二维码图片地址
    public function getWechatImage($key): string|array
    {
        $wechat = $this->wechat ? json_decode($this->wechat, true) : [];
        if (isset($wechat[$key])) {
            return [getAliOssUrl($wechat[$key])];
        }
        return '';
    }
}
